import constant from '@/store/constant.js'
import common from '@/store/common.js'
const baseUrl=constant.baseUrl;
const authInfo=constant.authInfo;

export default {
	state:{//存放状态
	
		doingList:[],
		doneList:[],
		
		
	},
	mutations: {
		
		doingAlertData(state,data){
		
			state.doingList=[]
			for(let index in data){
				state.doingList.push(data[index])
			}
		
		
			
		},
		doneAlertData(state,data){
		
			state.doneList=[]
			for(let index in data){
				state.doneList.push(data[index])
			}
		
		
			
		},
		
	},
	actions:{
		
		loadAlertData(context,data){
			
			data.status=0;
			//这个地方查所有未完成的目标
			uni.request({
				url: baseUrl+'/api/alert/listForPage',
				method: 'POST',
				header: {
				        'auth': uni.getStorageSync("token") 
				    },
				data: data,
				success: (res) => {
					if(res.data.code==0){
					
						context.commit('doingAlertData',res.data.result.data)
						
					}else{
						// console.log(res.data.message);
					}
			
				},
				fail: (err) => {
					common.jumpToLogin();
					console.log(err);
				}
			})
		data.status=1;
		//这个地方查所有未完成的目标
		uni.request({
			url: baseUrl+'/api/alert/listForPage',
			method: 'POST',
			header: {
			        'auth': uni.getStorageSync("token") 
			    },
			data: data,
			success: (res) => {
				if(res.data.code==0){
				
					context.commit('doneAlertData',res.data.result.data)
					
				}else{
					// console.log(res.data.message);
				}
		
			},
			fail: (err) => {
				common.jumpToLogin();
				console.log(err);
			}
		})
			
			
		},
		addAlertData(context,data){
			
			var url="";
			
			if(data.id.length>0){
				url=baseUrl+"/api/alert/editAlert";
			}else{
				url=baseUrl+"/api/alert/addAlert";
			}		
			uni.request({
				url: url,
				method: 'POST',
				header: {
				        'auth': uni.getStorageSync("token") 
				    },
				data:data,
				success: (res) => {
					if(res.data.code==0){
						context.dispatch('loadAlertData',{"pageNum":1,"pageSize":999})
						
					}else{
						common.dataError(res.data);
						console.log(res.data.message);
					}
			
				},
				fail: (err) => {
					common.jumpToLogin();
					console.log(err);
				}
			})
		},
		editAlertData(context,data){
			
			var url="";
			
			
			url=baseUrl+"/api/alert/updateStatus";
		
			uni.request({
				url: url,
				method: 'POST',
				header: {
				        'auth': uni.getStorageSync("token") 
				    },
				data:data,
				success: (res) => {
					if(res.data.code==0){
						// context.dispatch('loadAlertData',{"pageNum":1,"pageSize":999})
						
					}else{
						common.dataError(res.data);
						console.log(res.data.message);
					}
			
				},
				fail: (err) => {
					common.jumpToLogin();
					console.log(err);
				}
			})
		},
	}
}